﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XZL.GM.Dal;


namespace XZL.GM.Bll
{
    public class CourseInfoBiz
    {


        /// <summary>
        /// 获取课程分组列表
        /// </summary>
        /// <returns></returns>    
      public static List<Proc_CourseTeam_SelectListResult> GetCourseTeamList(int courseType,int pageIndex, int pageSize, ref int? pageCount)
      {
       CourseDataContext cd=new CourseDataContext();   
       return cd.Proc_CourseTeam_SelectList(courseType, pageIndex, pageSize, ref pageCount).ToList();
      }

      /// <summary>
      /// 获取课程分组信息 by courseID
      /// </summary>
      /// <param name="courseID"></param>
      /// <returns></returns>
      public static Proc_CourseTeam_SelectInfoResult GetCourseTeamInfo(int teamID)
      {
         CourseDataContext cd=new CourseDataContext();
         return  cd.Proc_CourseTeam_SelectInfo(teamID).FirstOrDefault();
      }

      /// <summary>
      /// 添加课程分组
      /// </summary>
      /// <param name="TeamID">用户ID</param>
      /// <returns>     </returns>
      /// 
     public static bool GetCourseTeamAdd(string teamName,int courseType,int sort,int status,string memo)
     {
        CourseDataContext cd=new CourseDataContext();
        cd.Proc_CourseTeam_Addition(teamName,courseType,sort,status,memo);
        return true;
     }


      /// <summary>
      /// 修改课程分组
      /// </summary>
      /// <param name="TeamID">用户ID</param>
      /// <returns>     </returns>
      /// 
     public static bool GetCourseTeamUpdate(int teamID,string teamName, int courseType, int sort, int status, string memo)
     {
         CourseDataContext cd = new CourseDataContext();
         cd.Proc_CourseTeam_Update(teamID,teamName, courseType, sort, status, memo);
         return true;
     }





        /// <summary>
        /// 获取课程列表
        /// </summary>
        /// <param name="courseName"></param>
        /// <param name="courseType"></param>
        /// <param name="isCharge"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>

      public static List<Proc_CourseInfo_SelectListResult> GetCourseList(string courseName, int courseType, int isCharge,int isLive, int pageIndex, int pageSize, ref int? pageCount)
        {
         XZL_GMDataContext db = new XZL_GMDataContext();
         return db.Proc_CourseInfo_SelectList(courseName, courseType, isCharge,isLive, pageIndex, pageSize, ref pageCount).ToList();
        }

      /// <summary>
      /// 获取最热课程 by courseID
      /// </summary>
      /// <param name="courseID"></param>
      /// <returns></returns>
    
      public static List<Proc_CourseInfo_HottestListResult> GetHottestList(int pageIndex, int pageSize, ref int? pageCount)
       {
        XZL_GMDataContext db = new XZL_GMDataContext();
        return db.Proc_CourseInfo_HottestList(pageIndex, pageSize, ref pageCount).ToList();
       }
      /// <summary>
      /// 获取最新课程 by courseID
      /// </summary>
      /// <param name="courseID"></param>
      /// <returns></returns>
      /// 
      public static List<Proc_CourseInfo_NewestListResult> GetNewestList(int pageIndex, int pageSize, ref int? pageCount)
       {
       XZL_GMDataContext db = new XZL_GMDataContext();
       return db.Proc_CourseInfo_NewestList(pageIndex, pageSize, ref pageCount).ToList();
       }

        /// <summary>
        /// 获取课程信息 by courseID
        /// </summary>
        /// <param name="courseID"></param>
        /// <returns></returns>
        public static Proc_CourseInfo_SelectInfoResult GetCourseInfo(int courseID)
        {
            XZL_GMDataContext db = new XZL_GMDataContext();
            return db.Proc_CourseInfo_SelectInfo(courseID).FirstOrDefault();
        }


        /// <summary>
        /// 获取课程类型列表
        /// </summary>
        /// <returns></returns>
        public static List<Proc_CourseType_SelectListResult> GetCourseTypeList()
       {
               XZL_GMDataContext db = new XZL_GMDataContext();
    
              return db.Proc_CourseType_SelectList().ToList();
        }

        /// <summary>
        /// 获取讲师列表
        /// </summary>
        /// <returns></returns>
        public static List<Proc_CourseTeacher_SelectListResult> GetCourseTeacherList()
        {
            XZL_GMDataContext db = new XZL_GMDataContext();

            return db.Proc_CourseTeacher_SelectList().ToList();
        }


        /// <summary>
        /// 添加课程
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <returns>     </returns>
        /// 
        public static bool CourseAddition(CourseInfo courseInfo)
        {
            XZL_GMDataContext db = new XZL_GMDataContext();

            db.Proc_CourseInfo_Addition(courseInfo.CourseName, courseInfo.CourseType, courseInfo.CourseTeamID, courseInfo.Price, courseInfo.StartTime,
                courseInfo.CourseImg, courseInfo.CourseInfoImg, courseInfo.Sort,courseInfo.TeacherID,  courseInfo.IsCharge,
                courseInfo.IsLive, courseInfo.CourseExplain, courseInfo.CourseIntroduce,courseInfo.VideoLink);

            return true;
        }

        /// <summary>
        /// 修改课程
        /// </summary>
        /// <param name="UserID">用户ID</param>
        /// <returns>     </returns>
        /// 
        public static bool CourseUpdate(CourseInfo courseInfo)
        {
            XZL_GMDataContext db = new XZL_GMDataContext();
            db.Proc_CourseInfo_Update(courseInfo.CourseID, courseInfo.CourseName, courseInfo.Price, courseInfo.StartTime,
             courseInfo.CourseImg, courseInfo.CourseInfoImg, courseInfo.CourseType,courseInfo.CourseTeamID, courseInfo.Sort, courseInfo.TeacherID,
             courseInfo.IsCharge,courseInfo.IsLive,courseInfo.VideoLink, courseInfo.CourseIntroduce, courseInfo.Status, courseInfo.IsInviteHelp,
             courseInfo.CourseExplain);
            return true;
        }

        /// <summary>
        /// 删除课程
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool DeleteCourse(int courseID)
        {
            XZL_GMDataContext db = new XZL_GMDataContext();
            db.Proc_Course_Delete(courseID);
            return true;
        }


        /// <summary>
        /// 更新推荐列表
        /// </summary>
        /// <param name="courseID"></param>
        /// <param name="RelatedCourse"></param>
        /// <returns></returns>
        public static bool UpdateRelated(int courseID,string RelatedCourse)
        {
            XZL_GMDataContext db = new XZL_GMDataContext();
            db.Proc_CouseInfo_UpdateRelated(courseID,RelatedCourse);
            return true;
        }


        /// <summary>
        /// 课程统计
        /// </summary>
        /// <param name="courseID"></param>     
        /// <returns></returns>
        public static List<Proc_CourseCount_SelectInfoResult> GetCourseCount(int type,string courseName, int courseType, DateTime courseStart, DateTime courseEnd, int pageIndex, int pageSize, ref int? pageCount)
        {
            Account_GMDataContext ax = new Account_GMDataContext();
            return ax.Proc_CourseCount_SelectInfo(type,courseName, courseType, courseStart, courseEnd, pageIndex, pageSize, ref pageCount).ToList();
          
        }


        public static List<Proc_CourseBuyNumber_SelectInfoResult> GetCourseBuyNumber(int pageIndex, int pageSize, ref int? pageCount)
        {
            Account_GMDataContext ax = new Account_GMDataContext();
            return ax.Proc_CourseBuyNumber_SelectInfo( pageIndex, pageSize, ref pageCount).ToList();

        }



        public static List<Proc_CourseBuyAmount_SelectInfoResult> GetCourseBuyAmount(int pageIndex, int pageSize, ref int? pageCount)
        {
            Account_GMDataContext ax = new Account_GMDataContext();
            return ax.Proc_CourseBuyAmount_SelectInfo(pageIndex, pageSize, ref pageCount).ToList();

        }


        /// <summary>
        /// 修改课程状态（删除）
        /// </summary>
        /// <returns></returns>
        public static bool ChangeStatus(string courseID, int status)
        {
            XZL_GMDataContext db = new XZL_GMDataContext();
            db.Proc_CourseStatus_UpdateCourse(courseID, status);
            return true;
        }

    }
}
